home *** CD-ROM | disk | FTP | other *** search
/ Chip: Special XP & Vista / Chip Spesial XP & Vista.iso / 3_Gadgets / UEFA_Informer_Gadget / UEFAinfo.gadget / scripts / settings.js < prev   
Text (UTF-16)  |  2008-03-24  |  7KB  |  111 lines

  1. function init_Settings()
  2. {
  3.     System.Gadget.onSettingsClosing = settings_Closing;
  4.     
  5.     var version = document.getElementById("version");
  6.     version.innerHTML = "version:  " + System.Gadget.version;
  7.     
  8.     get_Country();
  9. }
  10.  
  11. function get_Country()
  12. {
  13.     var country = document.getElementById("countryList");
  14.        country.innerHTML = "<p class='centered'><img src='images/loaderFly.gif'></p>";
  15.        
  16.     var httpreq = getHTTPObject();
  17.     var url = "http://soccerdb.890m.com/xml/countrylist.xml";
  18.     httpreq.open("GET", url, true);
  19.     httpreq.onreadystatechange = function ()
  20.     {
  21.         if (httpreq.readyState == 4)
  22.         {
  23.           if (httpreq.status == 200)
  24.           {
  25.                var xml = httpreq.responseXML;  
  26.             create_List(xml);
  27.           } else
  28.             {
  29.             country.innerHTML = "<p class='centered'>Error: Status " + httpreq.status + "  (" + httpreq.statusText + ")</p>";
  30.             }            
  31.         }
  32.     }
  33.     httpreq.send ();
  34. }
  35.  
  36. function create_List(xml)
  37. {
  38.     var countryNode = xml.documentElement.getElementsByTagName("country");
  39.     var country = document.getElementById("countryList");
  40.     country.innerHTML = "";//Clean list
  41.     for (var i = 0; i < countryNode.length; i++)
  42.     {
  43.         var countryId     = getAttributeValue(countryNode[i], "id");
  44.         var countryName     = getChildNodeValue(countryNode[i], "name");
  45.         var countryLogo     = getChildNodeValue(countryNode[i], "logo");
  46.         var countryValue = countryId + ";" + countryName + ";" + countryLogo;
  47.         create_Input(i, countryValue, countryName, country);
  48.     }
  49.     // Check countries from main menu
  50.     var input = country.getElementsByTagName("input");
  51.     var checkedValue = System.Gadget.Settings.read("checkedValue").split(",");
  52.     for (var i = 0; i < input.length; i++)
  53.     {
  54.         for (var j = 0; j < checkedValue.length; j++)
  55.         {
  56.             if (checkedValue[j] == input[i].value) input[i].checked = true;
  57.         }
  58.     }    
  59. }
  60.  
  61. function create_Input(id, value, text, parentNode)
  62. {
  63.     var input      = document.createElement("input");
  64.     input.type     = "checkbox";
  65.     input.value = value;
  66.     input.id    = "inp" + id;
  67.     parentNode.appendChild(input);
  68.     var label      = document.createElement("label");
  69.     label.htmlFor = "inp" + id;
  70.     parentNode.appendChild(label);
  71.     var textNode = document.createTextNode(text);
  72.     label.appendChild(textNode);
  73.     label.insertAdjacentHTML("afterEnd", "<br>");
  74. }
  75.  
  76. function check_All()
  77. {
  78.     var country = document.getElementById("countryList");
  79.     var input = country.getElementsByTagName("input");
  80.     var checkAll = document.getElementById("checkAll");
  81.     for (var i = 0; i < input.length; i++)
  82.     {
  83.         input[i].checked = checkAll.checked;
  84.     }
  85. }
  86.  
  87. function settings_Closing(event)
  88. {
  89.     if (event.closeAction == event.Action.commit) save_Settings();
  90.     event.cancel = false;
  91. }
  92.  
  93. function save_Settings() 
  94. {
  95.     var country = document.getElementById("countryList");
  96.     var input = country.getElementsByTagName("input");
  97.     var j = 0;
  98.     var checkedValue = [];
  99.     for (var i = 0; i < input.length; i++)
  100.     {
  101.         if (input[i].checked)
  102.         {
  103.             checkedValue[j] = input[i].value;
  104.             j++;
  105.         }
  106.     }
  107.     System.Gadget.Settings.write("checkedValue", checkedValue);
  108.     System.Gadget.Settings.write("countrySelId", "");
  109.     System.Gadget.Settings.write("numSelOption", "");
  110.     System.Gadget.document.parentWindow.init_Menu();
  111. }